using Digitalmes.Application.Scada.Models;
using Digitalmes.Application.Scada.Services;

namespace Digitalmes.Application.Scada.Commands;

/// <summary>
/// 不良品口返工后再上件请求命令处理者。
/// </summary>
internal sealed class ReworkFeedingCommandHandler(IServiceScopeFactory serviceScopeFactory) : IRequestHandler<ReworkFeedingCommand, ScadaResult>
{
    public async Task<ScadaResult> Handle(ReworkFeedingCommand request, CancellationToken cancellationToken)
    {
        using var scope = serviceScopeFactory.CreateScope();
        var service = scope.ServiceProvider.GetRequiredService<IReworkFeedingService>();
        ReworkFeedingInput input = new(request.LineCode, request.WsCode, request.SN);
        var result = await service.FeedingAsync(input, cancellationToken).ConfigureAwait(false);
        return result;
    }
}
